package com.demo.index;

import com.demo.common.model.User;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

public class LoginInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation invocation) {
        User user=invocation.getController().getSessionAttr("user");
        String controllerKey = invocation.getController().getControllerKey();
        if(user != null || controllerKey.equals("/")|| controllerKey.equals("/reg")){
            invocation.invoke();
        }else{
            invocation.getController().redirect("/");
        }
    }
}
